<?php
require_once '../config/db_config.php';

try {
    $conn = getDBConnection();
    
    // 检查是否已存在管理员账户
    $stmt = $conn->query("SELECT COUNT(*) FROM users WHERE role = 'admin'");
    $adminCount = $stmt->fetchColumn();
    
    if ($adminCount == 0) {
        // 创建默认管理员账户
        $username = 'admin';
        $password = password_hash('admin123', PASSWORD_DEFAULT);
        
        $stmt = $conn->prepare("INSERT INTO users (username, password, role) VALUES (?, ?, 'admin')");
        $stmt->execute([$username, $password]);
        
        echo "默认管理员账户创建成功！\n";
        echo "用户名: admin\n";
        echo "密码: admin123\n";
        echo "\n请立即登录并修改默认密码！";
    } else {
        echo "管理员账户已存在，无需初始化。";
    }
} catch(PDOException $e) {
    die("初始化失败: " . $e->getMessage());
}
?> 